package com.pig4cloud.pig.module.service.platform.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pig.module.api.entity.estate.Estate;
import com.pig4cloud.pig.module.api.entity.platform.PlatformPay;
import com.pig4cloud.pig.module.mapper.estate.EstateMapper;
import com.pig4cloud.pig.module.mapper.platform.PlatformPayMapper;
import com.pig4cloud.pig.module.service.platform.IPlatformPayService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * 银行支付列Service业务层处理
 *
 * @author ruoyi
 * @date 2022-09-13
 */
@Service
public class PlatformPayServiceImpl extends ServiceImpl<PlatformPayMapper, PlatformPay> implements IPlatformPayService {

	@Resource
	private PlatformPayMapper platformPayMapper;
	@Resource
	private EstateMapper estateMapper;

	@Override
	public PlatformPay getDefaultAccount() {
		QueryWrapper<PlatformPay> qw = new QueryWrapper<>();
		qw.eq("is_default",1);
		qw.last("limit 1");
		PlatformPay platformPay = platformPayMapper.selectOne(qw);
		return platformPay;
	}


	@Override
	public String orderQuery(String out_trade_no, PlatformPay platformPay) {
		String responseData = null;
		try {
//			responseData = NSQuery.queryOrder(out_trade_no,platformPay);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return responseData;
	}

	/**
	 * 退款
	 * @param out_trade_no
	 * @param refund_money
	 * @param out_refund_no
	 * @param platformPay
	 * @return
	 */
	@Override
	public String refundOrder(String out_trade_no, BigDecimal refund_money, String out_refund_no, PlatformPay platformPay) {
		String responseData = null;
		try {
//			responseData = NSRefund.refundOrder(out_trade_no,refund_money,out_refund_no,platformPay);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return responseData;
	}

	@Override
	public String refundOrderQuery(String out_trade_no, PlatformPay platformPay) {
		String responseData = null;
		try {
//			responseData = NSRefundQuery.queryOrder(out_trade_no,platformPay);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return responseData;
	}


	@Override
	public PlatformPay getAccountByEstateId(int estateId) {
		PlatformPay platformPay = null;
		Estate estate = estateMapper.selectById(estateId);
		if(estate!=null){
			platformPay = platformPayMapper.selectById(estate.getPayPlatformId());
		}
		return platformPay;
	}

}
